const fs = require('fs');
//传统回调的形式
fs.readFile('/Users/wangzhiyuan/Documents/myfile/js/thinking-in-java-script/promise/hello.txt', (err, data) => {
    if (err) throw err;
    console.log(data.toString())
})

//Promise形式
let p = new Promise((resolve, reject) => {
    fs.readFile('/Users/wangzhiyuan/Documents/myfile/js/thinking-in-java-script/promise/hello.txt', (err, data) => {
        if (err) {
            reject(err)
        } else {
            resolve(data)
        }
    })
})
p.then(value => {
    console.log(value.toString())
}, reason => {
    console.warn(reason.toString())
})
